// react + ts
// 根据初始值自动推断
// 场景：明确的初始值
import { useState } from 'react'

type User = {
  name: string,
  age: number
}
function App() {
  // 1. 限制初始值类型
  // const [user, setUser] = useState<User>({
  //   name: 'zhangsan',
  //   age: 18
  // })

  const [user, setUser] = useState<User>(()=>(
    {
      name: 'zhangsan',
      age: 18
    }
  ))

  // const changeUser = () => {
  //   setUser({
  //     name: 'lisi',
  //     age: 20
  //   })
  // }

  const changeUser = () => {
    setUser(()=>({
      name: 'lisi',
      age: 20
    }))
  }
  
  return (
    <>
      this is app, {user.name}
    </>
  )
}

export default App
